package com.x.erp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.MultilevelActivityAccount;
import com.x.erp.model.MultilevelActivityDetail;
import com.x.erp.rpc.MultilevelActivityAccountRpcService;
import com.x.erp.rpc.MultilevelActivityDetailRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 多级营销活动账户记录信息
 */
@RestController
@RequestMapping("/multilevelActivityAccount")
public class MultilevelActivityAccountController extends BaseController{

	@Reference
	private MultilevelActivityAccountRpcService multilevelActivityAccountRpcService;// 多级营销活动账户记录信息服务

	@Reference
	private MultilevelActivityDetailRpcService multilevelActivityDetailRpcService;// 多级营销活动账户明细记录信息服务

	/**
	 * 查询多级营销活动账户记录信息列表
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getMultilevelActivityAccountList", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getMultilevelActivityAccountList(MultilevelActivityAccount multilevelActivityAccount) {
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", multilevelActivityAccountRpcService.selectMultilevelActivityAccountList(multilevelActivityAccount));
	}

	/**
	 * 查询多级营销活动账户记录信息数量
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getMultilevelActivityAccountNum", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getMultilevelActivityAccountNum(MultilevelActivityAccount multilevelActivityAccount) {
		Map<String, Object> res = new HashMap<>();
		res.put("total", multilevelActivityAccountRpcService.selectMultilevelActivityAccountNum(multilevelActivityAccount));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", res);
	}

	/**
	 * 查询多级营销活动账户明细记录信息列表
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getMultilevelActivityDetailList", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getMultilevelActivityDetailList(MultilevelActivityDetail multilevelActivityDetail) {
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", multilevelActivityDetailRpcService.selectMultilevelActivityDetailList(multilevelActivityDetail));
	}

	/**
	 * 查询多级营销活动账户明细记录信息数量
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getMultilevelActivityDetailNum", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getMultilevelActivityDetailNum(MultilevelActivityDetail multilevelActivityDetail) {
		Map<String, Object> res = new HashMap<>();
		res.put("total", multilevelActivityDetailRpcService.selectMultilevelActivityDetailNum(multilevelActivityDetail));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", res);
	}

	/**
	 * 根据ID查询多级营销活动账户记录信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getMultilevelActivityAccount", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getMultilevelActivityAccount(MultilevelActivityAccount multilevelActivityAccount) {
		if(multilevelActivityAccount == null || StringUtils.isEmpty(multilevelActivityAccount.getUserId())) {
			return new ResultModel(ResultCode.RESULT_FAIL, "用户ID不能为空！");
		}
		//查询app当前版本
		List<MultilevelActivityAccount> multilevelActivityAccounts = multilevelActivityAccountRpcService.selectMultilevelActivityAccountList(multilevelActivityAccount);
		if(multilevelActivityAccounts != null && multilevelActivityAccounts.size() > 0) {
			return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", multilevelActivityAccounts.get(0));
		}
		return new ResultModel(ResultCode.RESULT_FAIL, "查询失败");
	}

	/**
	 * 新增多级营销活动账户记录信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/insertMultilevelActivityAccount", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel insertMultilevelActivityAccount(MultilevelActivityAccount multilevelActivityAccount) {
		if(multilevelActivityAccount == null) {
			return new ResultModel(ResultCode.RESULT_FAIL, "多级营销活动账户记录信息不能为空！");
		}
		if(StringUtils.isEmpty(multilevelActivityAccount.getUserId())) {
			return new ResultModel(ResultCode.RESULT_FAIL, "用户ID不能为空！");
		}
		MultilevelActivityAccount account = new MultilevelActivityAccount();
		account.setUserId(multilevelActivityAccount.getUserId());
		Date cDate = this.getDate(0);
		multilevelActivityAccount.setAccountCreateTime(cDate);
		multilevelActivityAccount.setAccountUpdateTime(cDate);
		return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功！", multilevelActivityAccountRpcService.insertMultilevelActivityAccount(multilevelActivityAccount));
	}


}
